package com.msb.Automatic;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: xw
 * @create: 2022/8/31 14:04
 * @description:
 */
public class AtomicIntegerTest {
    AtomicInteger count = new AtomicInteger();
    void m(){
        for (int i = 0; i <100 ; i++) {
            count.incrementAndGet();//count++
        }
    }
    public static void main(String[] args) {
        AtomicIntegerTest t = new AtomicIntegerTest();

        ArrayList<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            threads.add(new Thread(t::m, "thread-" + i));
        }
        threads.forEach((o) -> o.start());
        threads.forEach((o) -> {
            try {
                o.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println(t.count);

    }
}
